import { ipcMain } from "electron";
import Store from "electron-store";

export const store = new Store();

export function initStoreIpc() {
  ipcMain.handle("store-get", (e, key) => {
    try {
      const res = store.get(key);
      return res;
    } catch (e) {
      console.log("store get err: ", e);
    }
  });
  ipcMain.handle("store-set", (e, key, value) => {
    try {
      if (value === null || value === undefined) {
        store.delete(key);
      } else {
        store.set(key, value);
      }
    } catch (e) {
      console.log("store set err: ", e);
    }
  });
}
